import { Injectable } from '@angular/core';
import { Observable, of, timer } from 'rxjs';
import { delay } from 'rxjs/operators';

@Injectable({
  providedIn: 'root',
})
export class MockService {
  constructor() {}

  queryData1(params: { code: string; name: string;}) {
    const data = {
      code: '00000',
      message: 'success',
      value: this.getValueByParam(params),
    };
    return of(data).pipe(delay(1000));
  }

  queryData2(params: { code: string; name: string }) {
    const data = {
      code: '00000',
      message: 'success',
      value: this.getValueByParam(params),
    };
    return of(data).pipe(delay(1000));
  }

  queryData3(params: { code: string; name: string }) {
    const data = {
      code: '00000',
      message: 'success',
      value: this.getValueByParam(params),
    };
    return of(data).pipe(delay(1000));
  }

  getValueByParam(params: { code: string; name: string }) {
    let value: { id: string; name: string }[] = [];
    for (let i = 0; i < 10; i++) {
      let obj = {
        id: `${i}`,
        name: `${params.code}----${params.name}----${i}`,
        code: i % 2 == 0 ? 'button' : 'icon',
      };
      value.push(obj);
    }
    return value;
  }
}
